//
//  NIMBusinessOperationBox.m
//  qbnimclient
//
//  Created by 秦雨 on 17/11/21.
//  Copyright © 2017年 秦雨. All rights reserved.
//

#import "NIMBusinessOperationBox.h"
#import "NIMGlobalProcessor.h"

@implementation NIMBusinessOperationBox
SingletonImplementation(NIMBusinessOperationBox)

-(void)getFreeWaiter:(int64_t)bid wid_list:(NSArray *)wid_list
{
    [[NIMGlobalProcessor sharedInstance].businessProcessor getFreeWaiter:bid wid_list:wid_list];
}

-(void)setBusinessInfo:(SSIMBusinessInfo *)info
{
    NSMutableArray *list = [NSMutableArray arrayWithCapacity:10];
    NSArray *wids = info.waiters;
    for (NSDictionary *dict in wids) {
        int64_t wid = [[dict objectForKey:@"wid"] longLongValue];
        NSString *name = [dict objectForKey:@"widname"];
        [list addObject:@(wid)];
        NWaiterEntity *waiterEntity = [NWaiterEntity findFirstWithBid:info.bid wid:wid];
        if (waiterEntity == nil) {
            waiterEntity = [NWaiterEntity NIM_createEntity];
            waiterEntity.bid = info.bid;
            waiterEntity.wid = wid;
        }
        waiterEntity.name = name;
    }
    NBusinessEntity *business = [NBusinessEntity instancetypeFindBid:info.bid];
    if (business == nil) {
        business = [NBusinessEntity NIM_createEntity];
        business.bid = info.bid;
    }
    business.name = info.name;
    business.avatar = info.avatar;
    business.wids = list;
    
    [[NIMGlobalProcessor sharedInstance].businessProcessor setBusinessInfo:info];
}

-(void)getBusinessInfo:(int64_t)sellerid
{
    [[NIMGlobalProcessor sharedInstance].businessProcessor getBusinessInfo:sellerid];
}
@end
